package com.myweb.action.sys;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.myweb.action.BaseAction;
import com.myweb.common.Constants;
import com.myweb.entity.sys.SysUser;
import com.myweb.service.sys.ISysMenuService;
import com.myweb.service.sys.ISysUserService;

/**
 * 
 * @TODO  登录处理
 * @author roye
 * @date Apr 17, 2013 4:16:36 PM
 * @version V1.0
 */
@Controller("com.myweb.sys.loginAct")
public class LoginAction extends BaseAction{
	

	private String username;

	private String password;
	
	private SysUser user;
	
	@Autowired
	private ISysUserService isysUserService;
	
	@Autowired
	private ISysMenuService isysMenuService;
	
	/**
	 * 
	* @todo  登录
	* @author roye
	* @date Apr 17, 2013 4:25:06 PM
	* @param   
	* @return String   
	* @throws
	 */
	public String login(){
		username = user.getLoginName();
		password = user.getUserPwd();
		SysUser sysUser = this.isysUserService.getSysUser(username, password);
		if (sysUser==null) {
			this.setRequestAttribute("msg","用户名或密码错误！");
			return SUCCESS;
		}
		this.setSessionAttribute(Constants.LOGIN_PERSON_ID, sysUser.getUserId());
		this.setSessionAttribute(Constants.LOGIN_PERSON_NAME, sysUser.getUserName());
		String rstString = this.isysMenuService.getPrivilegeMenuByUser(sysUser);
		this.setRequestAttribute("menuJson", rstString);
		return SUCCESS;
	}
	
	/**
	 * 
	 * @todo 初始化左帧
	 * @author roye
	 * @date Apr 18, 2013 2:42:15 PM
	 * @param   
	 * @return String   
	 * @throws
	 */
	public String toLeft(){
		SysUser sysUser = new SysUser();
		sysUser.setUserId(Integer.parseInt(this.getSessionAttribute(Constants.LOGIN_PERSON_ID).toString()));
		String rstString = this.isysMenuService.getPrivilegeMenuByUser(sysUser);
		this.setRequestAttribute("menuJson", rstString);
		return "toLeft";
	}
	
	/**
	 * 
	 * @todo 初始化顶帧
	 * @author roye
	 * @date Apr 18, 2013 2:42:15 PM
	 * @param   
	 * @return String   
	 * @throws
	 */
	public String toTop(){
		return "toTop";
	}
	
	/**
	 * 
	 * @todo 初始化bar条
	 * @author roye
	 * @date Apr 24, 2013 2:42:54 PM
	 * @param   
	 * @return String   
	 * @throws
	 */
	public String toBar(){
		return "toBar";
	}
	
	/**
	 * 
	 * @todo 初始化center帧
	 * @author roye
	 * @date Apr 18, 2013 2:42:15 PM
	 * @param   
	 * @return String   
	 * @throws
	 */
	public String toCenter(){
		return "toCenter";
	}
	
	/**
	 * 
	 * @todo 初始化底帧
	 * @author roye
	 * @date Apr 18, 2013 2:42:15 PM
	 * @param   
	 * @return String   
	 * @throws
	 */
	public String toBottom(){
		return "toBottom";
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}



	public SysUser getUser() {
		return user;
	}



	public void setUser(SysUser user) {
		this.user = user;
	}

}
